function move(result, text) {
	var str = '<div class="move ' + result + '" >' + text + '</div>';
	if($(".move." + result).length > 0) {
		$(".move." + result).html(text).show();
	} else {
		$("body").append(str);
	}

	setTimeout(function() {
		$(".move." + result).fadeOut(2000);
	}, 1000);
}

function select(list) {
	var str = "";
	console.log(list.length);
	for(var i = 0; i < list.length; i++) {
		str += '<option value="' + list[i].id + '">' + list[i].name + '</option>';
	}
	return str;
}

function deleteModal(jsonObj, fun) {
	if($("#" + jsonObj.name + "Modal").length > 0) {
		$("#" + jsonObj.name + "Modal").find("input[name=id]").val(jsonObj.arg.id);
		console.log($("#" + jsonObj.name + "Modal").find("[name=name]"))
		$("#" + jsonObj.name + "Modal").find("[name=name]").html(jsonObj.arg.name);
	} else {
		var str = '<div class="modal fade parents" id="' + jsonObj.name + 'Modal">\
					<div class="modal-dialog">\
						<div class="modal-content">\
							<div class="modal-header">\
								<button type="button" class="close" data-dismiss="modal" aria-label="Close">\
	                  				<span aria-hidden="true">&times;</span>\
								</button>\
								<h4 class="modal-title">' + jsonObj.title + '</h4>\
							</div>\
							<div class="modal-body">\
								<form class="form-horizontal">\
									<div class="box-body">\
										<input type="hidden" name="id" value="' + jsonObj.arg.id + '"/>\
										<p>是否' + jsonObj.title + '“<span name="name">' + jsonObj.arg.name + '</span>”</p>';
										
										if(jsonObj.needPassword){
											str+='<input type="password" class="form-control" name="OPassword" placeholder="请输入操作密码"/>';
										}
									str+='</div>\
								</form>\
							</div>\
							<div class="modal-footer">\
								<button type="button" class="btn btn-primary save" onclick=' + fun + '()>确定</button>\
							</div>\
						</div>\
					</div>\
				</div>';
		$("body").append(str)
	}
	$("#" + jsonObj.name + "Modal").modal("show");
}

function addModal(jsonObj, fun) {
	if($("#" + jsonObj.name + "Modal").length > 0) {
		$("#" + jsonObj.name + "Modal").find("input[type=text]").val("");
		$("#" + jsonObj.name + "Modal").find("textarea").val("");
		$("#" + jsonObj.name + "Modal").find("input[type=radio]").prop("checked", false);
	} else {
		var str = '<div class="modal fade parents" id="' + jsonObj.name + 'Modal">\
			<div class="modal-dialog">\
			<div class="modal-content">\
			<div class="modal-header">\
			<button type="button" class="close" data-dismiss="modal" aria-label="Close">\
	        <span aria-hidden="true">&times;</span>\
			</button>\
			<h4 class="modal-title">' + jsonObj.title + '</h4>\
			</div>\
			<div class="modal-body">\
			<div class="row">';
		$.each(jsonObj.arg, function(index, item) {
			switch(item.type) {
				case "text":
					str += '<label class="margin-bottom-none col-xs-12"  >' + item.name + '<input type="text" class="form-control" name="' + index + '"/></label>'
					break;

				case "radio":
					//type:"radio",radio:[{title:"",value:""}]
					str += '<div class="col-xs-12" style="line-height: 2;">' + item.name + ':<div class="col-xs-12" style="padding: 0;">';
					$.each(item.radio, function(key, items) {
						str += '<label class="margin-r-5" style="font-weight: normal;"><input type="radio" name="' + index + '" value="' + items.value + '" style="margin:0 5px 0 0;"/>' + items.title + '</label>';
					});
					str += '</div></div>';
					break;

				case "textarea":
					str += '<label class="margin-bottom-none col-xs-12"  >' + item.name + '<textarea type="text" class="form-control" name="' + index + '" style="width:100%;"></textarea></label>';

					break;

				case "select":
					console.log(item.list);
					str += '<div class="form-group col-xs-12"><label class="control-label" style="font-weight:normal;">' + item.name + '</label><select name="' + index + '" class="form-control">';
					str += select(item.list);
					str += '</select></div>';

					break;

				case "file":

					str += '<label class="margin-bottom-none col-xs-12"  >' + item.name + '<input type="file" class="form-control" name="' + index + '"/></label>';
					break;

				default:
					str += '';
			}

		})

		str += '</div></div><div class="modal-footer"><button type="button" class="btn btn-primary save" onclick=' + fun + '()>确定</button></div></div></div></div>';
		$("body").append(str)
	}
	$("#" + jsonObj.name + "Modal").modal("show");
}

function editModal(jsonObj, fun) {
	if($("#" + jsonObj.name + "Modal").length > 0) {
		$("#" + jsonObj.name + "Modal").find("input").val("");
		$.each(jsonObj.arg,function(index,item){
			$("#"+jsonObj.name+"Modal").find("[name="+index+"]").val(item.value);
		})
	} else {
		var selectArr = {},radioArr={},
			str = '<div class="modal fade parents" id="' + jsonObj.name + 'Modal">\
				<div class="modal-dialog">\
				<div class="modal-content">\
				<div class="modal-header">\
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">\
	            <span aria-hidden="true">&times;</span>\
				</button>\
				<h4 class="modal-title">' + jsonObj.title + '</h4>\
				</div>\
				<div class="modal-body">\
				<div class="row">';

		$.each(jsonObj.arg, function(index, item) {

			switch(item.type) {

				case "id":

					str += '<input type="hidden" name="id" value="' + item.value + '">';
					break;

				case "text":
					str += '<label class="margin-bottom-none col-xs-12"  >' + item.name + '<input type="text" class="form-control" name="' + index + '" value="' + item.value + '"/></label>'
					break;

				case "textarea":
					str += '<label class="margin-bottom-none col-xs-12"  >' + item.name + '<textarea type="text" class="form-control" name="' + index + '" style="width:100%;">' + item.value + '</textarea></label>';

					break;

				case "select":
					selectArr[index] = item.value;
					console.log(item)
					str += '<div class="form-group col-xs-12"><label class="control-label" style="font-weight:normal;">' + item.name + '</label><select name="' + index + '" class="form-control">';
					str += select(item.list);
					str += '</select></div>';
					break;

				case "radio":
					radioArr[index]=item.value
					str += '<div class="col-xs-12" style="line-height: 2;">' + item.name + ':<div class="col-xs-12" style="padding: 0;">';
					$.each(item.radio, function(key, items) {
						console.log(items.value);
						
						str += '<label class="margin-r-5" style="font-weight: normal;"><input type="radio" name="' + index + '" value="' + items.value + '" style="margin:0 5px 0 0;"/>' + items.title + '</label>';
					});
					str += '</div></div>';
					break;

				case "file":

					str += '<label class="margin-bottom-none col-xs-12"  >' + item.name + '<input type="file" class="form-control" name="' + index + '"/></label>';;
					break;

				default:
					str += "";
			}
		})

		str += '</div></div><div class="modal-footer"><button type="button" class="btn btn-primary save" onclick=' + fun + '()>确定</button></div></div></div></div>';

		$("body").append(str);
		console.log(radioArr)
		$.each(selectArr, function(index, item) {
			$("#" + jsonObj.name + "Modal [name=" + index + "]").val(item);
		})
		$.each(radioArr, function(index, item) {
			$("#" + jsonObj.name + "Modal [name=" + index + "][value="+item+"]").prop("checked",true);
		})
	}
	$("#" + jsonObj.name + "Modal").modal("show");
}

//$("body").on("change", "input[type=file]", function() {
//	var sendData = new FormData();
//	var _this = $(this)
//	sendData.append('file', $(this)[0].files[0]);
//
//	$.ajax({
//		type: "post",
//		async: true,
//		processData: false,
//		contentType: false,
//		url: url + "/Web_UploadFile",
//		data: sendData,
//		dataType: "json",
//		success: function(res) {
//			if(res.status == 1) {
//				_this.attr("flie", res.data)
//			} else {
//				move("error", res.error);
//
//			}
//		}
//	})
//})